package com.jingtai.validate.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.http.HttpStatus;

@Data
@EqualsAndHashCode
@JsonInclude(Include.NON_EMPTY)
public class DataVo<T> {
	
	private Integer status = HttpStatus.OK.value();
	private String message;
	private Object data;

	public DataVo(Integer code, String message, T data) {
		this.status = code;
		this.message = message;
		this.data = data;
	}

	public DataVo(HttpStatus status) {
		this.status = status.value();
		this.message = status.getReasonPhrase();
	}

	public DataVo(HttpStatus status, T data) {
		this.status = status.value();
		this.message = status.getReasonPhrase();
		this.data = data;
	}

	public DataVo(String message) {
		this.message = message;
	}

	public DataVo(String message, T data) {
		this.message = message;
		this.data = data;
	}

	public DataVo(Integer code, String message) {
		this.status = code;
		this.message = message;
	}

	/**
	 * 可以在设置HttpStatus后单独设置message.
	 */
	public DataVo<T> message(String message) {
		this.message = message;
		return this;
	}

	/**
	 * 可以在设置HttpStatus后单独设置message.
	 */
	public DataVo<T> data(T data) {
		this.data = data;
		return this;
	}
}
